package asteroids.entity.equipment;

import org.apache.log4j.Logger;

import asteroids.engine.GameState;
import asteroids.entity.Ship;

public class ShivaFurnace extends Equipment
{
    private static final Logger logger = Logger.getLogger(ShivaFurnace.class);
    double cooldownTime;
    long lastTimeUsed = 0;

    private double powerRegenChunk;

    public ShivaFurnace(Ship ship, double chunk, double cooldown)
    {
        super(ship);
        powerRegenChunk = chunk;
        cooldownTime = cooldown;
        logger.trace("creating shiva furnace for " + ship + ". regen: " + chunk + "; delay: "
                + cooldown);
    }

    /*
     * You shouldn't use Utils.MILLISECONDS_PER_SECOND for timings, since game
     * performance can affect it. (if the game is running slow, it speeds up
     * real time, relatively speaking)
     */
    // public ShivaFurnace(Ship ship, double chunk)
    // {
    // super(ship);
    // powerRegenChunk = chunk;
    // cooldownTime = 0.33 * Utils.MILLISECONDS_PER_SECOND;
    // }
    //
    // public ShivaFurnace(Ship ship)
    // {
    // this(ship, 2, 0.33 * Utils.MILLISECONDS_PER_SECOND);
    // }

    @Override
    public void respawn()
    {
    }

    public void update(GameState state)
    {
        if( (state.currentGameTime() - lastTimeUsed) >= cooldownTime )
        {
            ship.modifyEnergyBy(powerRegenChunk);
            // lastTimeUsed = System.currentTimeMillis();
            lastTimeUsed += cooldownTime;
        }
    }
}